home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
MPW_TOOL
/
TOOLS
/
TOOLS_WI
/
ICON_8
/
CALLING_
/
EXTINT.C
< prev
next >
Wrap
Text File
|
1990-04-08
|
2KB
|
57 lines
/*
* Example of calling C functions by integer codes. Here it's
* one of three UNIX functions:
*
* 1: getpid (get process identification)
* 2: getppid (get parent process identification)
* 3: getpgrp (get process group)
*/
#include "../h/config.h"
#include "../h/rt.h"
#include "rproto.h"
struct descrip retval; /* for returned value */
dptr extcall(dargv, argc, ip)
dptr dargv;
int argc;
int *ip;
{
int retcode;
int getpid(), getppid(), getpgrp();
*ip = -1; /* anticipate error-free execution */
if (cvint(dargv) == CvtFail) { /* 1st argument must be a string */
*ip = 101; /* "integer expected" error number */
return dargv; /* return offending value */
}
switch ((int)IntVal(*dargv)) {
case 1: /* getpid */
retcode = getpid();
break;
case 2: /* getppid */
retcode = getppid();
break;
case 3: /* getpgrp */
if (argc < 2) {
*ip = 205; /* no error number fits, really */
return NULL; /* no offending value */
}
dargv++; /* get to next value */
if (cvint(dargv) == CvtFail) { /* 2nd argument must be integer */
*ip = 101; /* "integer expected" error number */
return dargv;
}
retcode = getpgrp(IntVal(*dargv));
break;
default:
*ip = 216; /* external function not found */
return NULL;
}
MakeInt(retcode,&retval); /* make an Icon integer for result */
return &retval;
}